<%
package webui

import (
  "net/http"
  "github.com/contribsys/faktory/client"
  "github.com/contribsys/faktory/util"
)

func ego_index(w io.Writer, req *http.Request) {
  ego_layout(w, req, func() { %>
    <%== LicenseStatus(w, req) %>
<script type="text/javascript" src="<%= relative(req, "/static/dashboard.js") %>"></script>
<div class= "dashboard clearfix">
  <h3 >
    <%= t(req, "Dashboard") %>
    <span class="beacon">
      <span class="ring"></span>
      <span class="dot"></span>
    </span>
  </h3>
  <div class="interval-slider ltr">
    <span class="interval-slider-label"><%= t(req, "PollingInterval") %>:</span>
    <span class="current-interval">5 sec</span>
    <br/>
    <input type="range" min="2000" max="20000" step="1000" value="5000"/>
  </div>
</div>

<div class="row chart">
  <div id="realtime" data-processed-label="<%= t(req, "Processed") %>" data-failed-label="<%= t(req, "Failed") %>"></div>
  <div id="realtime-legend"></div>
</div>

<div class="row chart">
  <h6>
    <span class="pe-3"><%= t(req, "History") %></span>
    <a href="<%= relative(req, "/?days=7") %>" class="history-graph <%= daysMatches(req, "7", false) %>"><%= t(req, "OneWeek") %></a>
    <a href="<%= relative(req, "/") %>" class="history-graph <%= daysMatches(req, "30", true) %>"><%= t(req, "OneMonth") %></a>
    <a href="<%= relative(req, "/?days=90") %>" class="history-graph <%= daysMatches(req, "90", false) %>"><%= t(req, "ThreeMonths") %></a>
    <a href="<%= relative(req, "/?days=180") %>" class="history-graph <%= daysMatches(req, "180", false) %>"><%= t(req, "SixMonths") %></a>
  </h6>

  <div id="history" data-processed-label="<%= t(req, "Processed") %>" data-failed-label="<%= t(req, "Failed") %>" data-processed="<%= processedHistory(req) %>" data-failed="<%= failedHistory(req) %>" data-update-url="<%= relative(req, "/stats") %>"></div>
  <div id="history-legend"></div>
</div>

<br/>
<div class="row">
  <div class="stat col-12 col-md-2">
    <div class="border pt-0 pt-md-2 mb-3">
      <h3 class="faktory_version"><%= client.Version %></h3>
      <p><%= t(req, "Version") %></p>
    </div>
  </div>

  <div class="stat col-12 col-md-2">
    <div class="border pt-0 pt-md-2 mb-3">
      <h3 class="uptime_in_days"><%= uptimeInDays(req) %></h3>
      <p><%= t(req, "Uptime") %></p>
    </div>
  </div>

  <div class="stat col-12 col-md-2">
    <div class="border pt-0 pt-md-2 mb-3">
      <h3 class="connections"><%= ctx(req).Server().Stats.Connections %></h3>
      <p><%= t(req, "Connections") %></p>
    </div>
  </div>

  <div class="stat col-12 col-md-2">
    <div class="border pt-0 pt-md-2 mb-3">
      <h3 class="used_memory_human"><%= util.MemoryUsageMB() %> MB</h3>
      <p><%= t(req, "MemoryUsage") %></p>
    </div>
  </div>

  <div class="stat col-12 col-md-2">
    <div class="border pt-0 pt-md-2 mb-3">
      <h3 class="commands"><%= ctx(req).Server().Stats.Commands %></h3>
      <p><%= t(req, "CommandsExecuted") %></p>
    </div>
  </div>
</div>
  <% }) %>
<% // vim: set ft=html %>
<% } %>
